package pqt;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.SwingConstants;
import java.awt.List;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class AtributoNoOk extends JDialog {

	private final JPanel contentPanel = new JPanel();
	final List listaTodos = new List();
	final List listaErrores = new List();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			AtributoNoOk dialog = new AtributoNoOk();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public AtributoNoOk() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(AtributoNoOk.class.getResource("/img/icono.png")));
		setBounds(100, 100, 844, 592);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
//---------------------------------------------------------------------------------------------------------		
		final JButton btnOk = new JButton("");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		
		btnOk.setFocusable(true);
		btnOk.setContentAreaFilled(false);
		btnOk.setBorderPainted(false);
		btnOk.setBorder(null);
		btnOk.setBounds(85, 435, 271, 75);
		btnOk.setIcon(new ImageIcon(testBoton.class.getResource("/img/AceptarAzulChico.png")));
		btnOk.setPressedIcon(new ImageIcon(testBoton.class.getResource("/img/AceptarBlancoChico.png")));
		btnOk.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent arg0) {
				btnOk.setIcon(new ImageIcon(testBoton.class.getResource("/img/AceptarVerdeChico.png")));
				getRootPane().setDefaultButton(btnOk);
				
			}
			@Override
			public void mouseExited(MouseEvent e) {
				btnOk.setIcon(new ImageIcon(testBoton.class.getResource("/img/AceptarAzulChico.png")));
				getRootPane().setDefaultButton(null);
			}
		});
		btnOk.addFocusListener(new FocusAdapter() {
			@Override
			public void focusGained(FocusEvent arg0) {
				btnOk.setIcon(new ImageIcon(testBoton.class.getResource("/img/AceptarVerdeChico.png")));
				getRootPane().setDefaultButton(btnOk);
			}
			@Override
			public void focusLost(FocusEvent e) {
				btnOk.setIcon(new ImageIcon(testBoton.class.getResource("/img/AceptarAzulChico.png")));
				getRootPane().setDefaultButton(null);
			}
		});
		contentPanel.add(btnOk);
//---------------------------------------------------------------------------------------------------------		
		
		final JButton btnCancelar = new JButton("");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnCancelar.setFocusable(true);
		btnCancelar.setContentAreaFilled(false);
		btnCancelar.setBorderPainted(false);
		btnCancelar.setBorder(null);
		btnCancelar.setBounds(444, 435, 271, 75);
		btnCancelar.setIcon(new ImageIcon(testBoton.class.getResource("/img/CancelarAzulChico.png")));
		btnCancelar.setPressedIcon(new ImageIcon(testBoton.class.getResource("/img/CancelarBlancoChico.png")));
		btnCancelar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent arg0) {
				btnCancelar.setIcon(new ImageIcon(testBoton.class.getResource("/img/CancelarRojoChico.png")));
				getRootPane().setDefaultButton(btnCancelar);
				
			}
			@Override
			public void mouseExited(MouseEvent e) {
				btnCancelar.setIcon(new ImageIcon(testBoton.class.getResource("/img/CancelarAzulChico.png")));
				getRootPane().setDefaultButton(null);
			}
		});
		btnCancelar.addFocusListener(new FocusAdapter() {
			@Override
			public void focusGained(FocusEvent arg0) {
				btnCancelar.setIcon(new ImageIcon(testBoton.class.getResource("/img/CancelarRojoChico.png")));
				getRootPane().setDefaultButton(btnCancelar);
			}
			@Override
			public void focusLost(FocusEvent e) {
				btnCancelar.setIcon(new ImageIcon(testBoton.class.getResource("/img/CancelarAzulChico.png")));
				getRootPane().setDefaultButton(null);
			}
		});
		contentPanel.add(btnCancelar);
		
		
		listaTodos.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent key) {
				if(key.getKeyCode() == KeyEvent.VK_ENTER)
				{
					agregarItem();
				}
					
			}
		});
		listaTodos.setFont(new Font("Dialog", Font.PLAIN, 35));
		listaTodos.setBounds(54, 10, 302, 406);
		listaTodos.add("Atributo 1");
		listaTodos.add("Atributo 2");
		listaTodos.add("Atributo 3");
		listaTodos.add("Atributo 4");
		listaTodos.add("Atributo 5");
		listaTodos.select(0);
		contentPanel.add(listaTodos);
		listaErrores.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent key) {
				if(key.getKeyCode() == KeyEvent.VK_ENTER)
				{
					quitarItem();
				}
			}
		});
		
		
		listaErrores.setFont(new Font("Dialog", Font.PLAIN, 35));
		listaErrores.setBounds(460, 10, 302, 406);
		contentPanel.add(listaErrores);
		
		JButton btnAgregar = new JButton(">>");
		btnAgregar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				agregarItem();
			}

			
		});
		btnAgregar.setBounds(362, 193, 89, 23);
		contentPanel.add(btnAgregar);
		
		JButton button = new JButton("<<");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				quitarItem();
			}
		});
		button.setBounds(362, 238, 89, 23);
		contentPanel.add(button);
		
		
	}

	private void agregarItem() {
		if(listaTodos.getSelectedIndex()!=-1)
		{
			int i;
			boolean existe=false;
			for(i=0;i<listaErrores.countItems();i++)
			{
				//System.out.println(listaErrores.getItem(i).toString());
				if(listaErrores.getItem(i).toString() == listaTodos.getItem(listaTodos.getSelectedIndex()))
				{
					existe=true;
				}
			}
			if(!existe)
			listaErrores.add(listaTodos.getItem(listaTodos.getSelectedIndex()));
			
		}
		
	}//fin agregar item
	
	private void quitarItem(){
		if(listaErrores.getSelectedIndex()!=-1)
		{
			listaErrores.remove(listaErrores.getItem(listaErrores.getSelectedIndex()));
	
		}
	}
}
